<?php

$strName = $_POST["tName"];
$strMessage = $_POST["tMessage"];
$Message = $_POST["i"];


$strFileName = "Chat.txt";

if ($strName != "" and $strMessage != "") {
    //*** Write Text file ***//
    $objFopen = fopen("Chat/" . $strFileName, 'a');
    $strText1 = "$strName พูดว่า : $strMessage\r\n";    
    fwrite($objFopen, $strText1);
    fclose($objFopen);
      
}
if($Message == '50'){
     $objFopen = fopen("Chat/" . $strFileName, 'w');
}


//*** Read Text file ***//
$objFopen = fopen("Chat/" . $strFileName, 'r');
if ($objFopen) {
    while (!feof($objFopen)) {
        $file = fgets($objFopen, 4096);
        echo $file . "<br>";
    }
    fclose($objFopen);
}

echo "<div id='mydiv'></div>";

?>